// sharing/pages/user/useredit/index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    app.getShareData(function(res){that.setData({cfg: res.data})});
	app.getUserInfo(function(openid){
		app.util.request({
			url: 'entry/wxapp/getUser',
			data: { openid: openid, m: 'junsion_wifinav'},
			cachetime: 0,
			success: function (res) {
				that.setData({user: res.data});
			}
		}); 
	});
    wx.getStorage({
      key: 'appcolor',
      success: function (res) {
        wx.setNavigationBarColor({
          frontColor: '#ffffff',
          backgroundColor: res.data,
        })
        that.setData({ 'appColor': res.data });
      },
    })
  },
  confirmSubmit: function (e){
	var data = {
		openid: this.data.user.openid,
		realname: e.detail.value.u_name,
		mobile: e.detail.value.u_phone,
		gender: e.detail.value.u_sex,
		address: e.detail.value.u_address,
		introduce: e.detail.value.u_introduce,
		m: 'junsion_wifinav'
	};
	wx.showLoading({title: '请稍后...'});
	app.util.request({
		url: 'entry/wxapp/updateUser',
		data: data,
		cachetime: 0,
		success: function (res) {
			wx.hideLoading();
			wx.showModal({
			  title: '温馨提示',
			  content: '资料更新成功',
			  showCancel: false,
			  success: function(res){
				  if(res.confirm){
					wx.setStorageSync('setUser',1);
					wx.navigateBack({
						data: 1
					});
				  }
			  }
			});
		}
	});
  },
  onShareAppMessage: function () {
	  return {
	      title: this.data.cfg.indexShare,
	      path: '/sharing/pages/index/index',
	      success: function(res) {
	        // 转发成功
	      },
	      fail: function(res) {
	        // 转发失败
	      }
	    }
  }
})